Special Variables in Perl

Special Variables

SPECIAL VARIABLES
$_    default variable
$0    program name
$/    input separator
$\    output separator
$|    autoflush
$!    sys/libcall error
$@    eval error
$$    process ID
$.    line number
@ARGV command line args
@INC  include paths
@_    subroutine args
%ENV  environment

ref: http://docs.rinet.ru/ProPauk/ch8.htm

$INPUT_RECORD_SEPARATOR

Short Name: $/

Definition

By default, an input file is split into records, each of which comprises one line. The input-record separator is a newline character. This variable can be set to have no value (in which case entire input files are read in at the same time) or to have other values, as required.

Example

undef $/;
open(INFILE,"infile.tst");
$buffer = <INFILE>;
print "$buffer\n";

$INPUT_LINE_NUMBER

Short Name: $.

Definition

This variable counts the number of lines of input from a file and is reset when the file is closed. The variable counts lines cumulatively across all input files read with the <> construct because these are not closed explicitly.

Example

print "The last file read had $. lines\n";
Homepage
Comments

Hide Comments